#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 2e5 + 10;
long long int f[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        long long int x = 0;
        cin >> x;
        f[i] = f[i - 1] + x;
    }
    long long int prev = 0;
    long long int ret = -1e20;
    for (int i = 1; i <= n; i++)
    {
        ret = max(ret, f[i] - prev);
        prev = min(prev, f[i]);
    }
    cout << ret;
    return 0;
}